"use strict";
/* Controllers */
app.controller("helpdocAddController", ['$scope', '$location', '$rootScope', '$routeParams', 'helpdocAddService', function ($scope, $location, $rootScope, $routeParams, helpdocAddService) {

    var vm = $scope.vm = {};
    vm.p = {};
    vm.p.id = $routeParams.id; // 如果ID!=0为更新

    vm.p.action = 0;

    var errorFn = function (result) {
        alert(result);
    };

    $scope.setHelpdoc = function () {
        var vm = $scope.vm;
        var params = vm.p;
        var procFn = function (response) {
            if (response.success && response.data) {
                //window.location = "#/star/helpdoc/helpdoc_list";
                alert("执行成功！")
            } else {
                alert(response.msg);
            }
        };
        helpdocAddService.setHelpdoc(params, procFn, errorFn);
    };
    $scope.getHelpdoc = function () {
        var vm = $scope.vm;
        var params = {
            id: vm.p.id
        };
        var procFn = function (response) {
            if (response.success && response.data) {
                //vm.p = JSON.stringify(response.data);
                vm.p = response.data;
            } else {
                alert(response.msg);
            }
        };
        helpdocAddService.getHelpdoc(params, procFn, errorFn);
    };

    //
    if(vm.p.id!=0) {
        $scope.getHelpdoc();
    }
}]);


/* Services */
app.service('helpdocAddService', ['ajaxService', function (ajaxService) {

    this.setHelpdoc = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/helpdoc/setHelpdoc.do", successFunction, errorFunction);
    };
    this.getHelpdoc = function (params, successFunction, errorFunction) {
        ajaxService.AjaxPost(params, "/star/api/basic-service/v1/helpdoc/getHelpdoc.do", successFunction, errorFunction);
    };
}]);

